local heju = fk.CreateSkill {
  name = "th_heju",
}

heju:addEffect(fk.EventPhaseProceeding, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(heju.name) and target.chained and target.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = heju.name,
      prompt = "#th_heju-add::" .. target.id
    })
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(target, MarkEnum.AddMaxCards, 1)
  end
})
heju:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(heju.name) then
      for _, move in ipairs(data) do
        if move.from and move.from ~= player and move.from.chained and move.from:getMaxCards() > 0 then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              if move.from:getHandcardNum() <= move.from.hp then
                event:setCostData(self, { tos = { move.from } })
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = heju.name,
      prompt = "#th_heju-sub::" .. event:getCostData(self).tos[1].id
    })
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(event:getCostData(self).tos[1], MarkEnum.MinusMaxCards, 1)
  end
})

Fk:loadTranslationTable{
  ["th_heju"] = "合局",
  [":th_heju"] = "横置角色的准备阶段，你可以令其手牌上限+1；横置的其他角色手牌数减少至不大于其体力值后，你可以令其手牌上限-1。",

  ["#th_heju-add"] = "合局：你可以令 %dest 的手牌上限+1",
  ["#th_heju-sub"] = "合局：你可以令 %dest 的手牌上限-1",
}

return heju